<template>
  <div>
    登录
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="活动名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <a> <li>456</li></a>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: '',
      },
      rules: {
        name: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
      },
    }
  },
  created() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!')
          // console.log(this.ruleForm.name)
          console.log()
          this.setCache('user', this.ruleForm.name)
          this.setCache('token', '78741654987548798')
          // window.localStorage.setItem('user', this.ruleForm.name)
          // if (this.getCache('user')) {
          this.$router.push('/home')
          var fakeRouter = {
            router: [
              {
                icon: 'el-icon-house',
                path: '/home',
                component: 'home',
                name: 'home',
                redirect: {
                  name: 'index',
                },
                children: [
                  {
                    icon: 'el-icon-discount',
                    path: 'index',
                    component: 'index',
                    name: 'index',
                  },
                  {
                    icon: 'el-icon-collection',
                    path: 'HW',
                    component: 'HelloWorld',
                    name: 'HW',
                  },
                  {
                    icon: 'el-icon-bank-card',
                    path: 'item',
                    component: 'item',
                    name: 'item',
                  },
                ],
              },
              {
                path: '/404',
                component: '404',
                name: '404',
              },
              {
                path: '*',
                redirect: '/404',
              },
            ],
          }
          this.setCache('router', fakeRouter.router)
          // } else {
          // }
          // setTimeout(() => {
          // }, 500)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
  },
}
</script>
<style scoped  lang="scss">
</style>